#!/bin/bash
# /**
# * Copyright (c) 2018, God's harbor
# * All rights reserved.
# * @file    change_types.sh
# * @brief   将代码中的C语言标准数据类型替换成自定的类型
# * @author  Jason Zhou,yzfcer@163.com
# * @version 1.0
# * @date    2021-09-15
# */


dir=$1
function replace_basic_type()
{
    replace_str.sh ${dir} "\t" "\ \ \ \ "
    replace_str.sh ${dir} "\<long \+double\>" swfp128_t
    replace_str.sh ${dir} "\<double\>" swfp64_t
    replace_str.sh ${dir} "\<float\>" swfp32_t

    replace_str.sh ${dir} "\<unsigned\ \+long\ \+long \+int\>" swu64_t
    replace_str.sh ${dir} "\<unsigned\ \+long\ \+long\>" swu64_t
    replace_str.sh ${dir} "\<unsigned\ \+long\ \+int\>" swu64_t
    replace_str.sh ${dir} "\<unsigned\ \+short \+int\>" swu16_t
    replace_str.sh ${dir} "\<unsigned\ \+long\>" swu64_t
    replace_str.sh ${dir} "\<unsigned\ \+int\>" swu32_t
    replace_str.sh ${dir} "\<unsigned\ \+short\>" swu16_t
    replace_str.sh ${dir} "\<unsigned\ \+char\>" swu8_t
    replace_str.sh ${dir} "\<unsigned\>" swu32_t

    replace_str.sh ${dir} "\<signed\ \+long\ \+long \+int\>" swi64_t
    replace_str.sh ${dir} "\<signed\ \+long\ \+long\>" swi64_t
    replace_str.sh ${dir} "\<signed\ \+long\ \+int\>" swi64_t
    replace_str.sh ${dir} "\<signed\ \+short \+int\>" swi16_t
    replace_str.sh ${dir} "\<signed\ \+long\>" swi64_t
    replace_str.sh ${dir} "\<signed\ \+int\>" swi32_t
    replace_str.sh ${dir} "\<signed\ \+short\>" swi16_t
    replace_str.sh ${dir} "\<signed\ \+char\>" swi8_t
    replace_str.sh ${dir} "\<signed\>" swi32_t

    replace_str.sh ${dir} "\<long\ \+long \+int\>" swi64_t
    replace_str.sh ${dir} "\<long\ \+long\>" swi64_t
    replace_str.sh ${dir} "\<long\ \+int\>" swi64_t
    replace_str.sh ${dir} "\<short \+int\>" swi16_t
    replace_str.sh ${dir} "\<long\>" swi64_t
    replace_str.sh ${dir} "\<int\>" swi32_t
    replace_str.sh ${dir} "\<short\>" swi16_t

    replace_str.sh ${dir} "\<too swi64_t\>" "too long"
    replace_str.sh ${dir} "\<too swi32_t\>" "too short"
    replace_str.sh ${dir} \<bool\> swbool_t
}

function replace_stdint_type()
{
    replace_str.sh ${dir} "\<uint64_t\>" swu64_t
    replace_str.sh ${dir} "\<uint32_t\>" swu32_t
    replace_str.sh ${dir} "\<uint16_t\>" swu16_t
    replace_str.sh ${dir} "\<uint8_t\>" swu8_t

    replace_str.sh ${dir} "\<int64_t\>" swi64_t
    replace_str.sh ${dir} "\<int32_t\>" swi32_t
    replace_str.sh ${dir} "\<int16_t\>" swi16_t
    replace_str.sh ${dir} "\<int8_t\>" swi8_t
}

function replace_ubus_struct()
{
    replace_str.sh ${dir} "\<struct \+ubus_object\>" ubus_object_t;
    replace_str.sh ${dir} "\<struct \+ubus_object_type\>" ubus_object_type_t;
    replace_str.sh ${dir} "\<struct \+ubus_mothod\>" ubus_mothod_t;
    replace_str.sh ${dir} "\<struct \+ubus_context\>" ubus_context_t
    replace_str.sh ${dir} "\<struct \+ubus_event_handler\>" ubus_event_hd_t
    replace_str.sh ${dir} "\<struct \+ubus_request_data\>" ubus_request_data_t
}

function replace_uci_struct()
{
    replace_str.sh ${dir} "\<struct \+uci_context\>" uci_context_t
    replace_str.sh ${dir} "\<struct \+uci_ptr\>" uci_ptr_t
    replace_str.sh ${dir} "\<struct \+uci_section\>" uci_section_t
    replace_str.sh ${dir} "\<struct \+uci_option\>" uci_option_t
    replace_str.sh ${dir} "\<struct \+uci_element\>" uci_element_t
    replace_str.sh ${dir} "\<struct \+uci_package\>" uci_package_t
}

function main()
{
    # replace_basic_type
    # replace_stdint_type
    # replace_ubus_struct
    # replace_uci_struct
}

main $@

